﻿Ext.define('app.prm.detail.EditInfo',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    //maximized: true,
    width: 800,
    height: 600,
    layout: 'fit',
    projectId: 0,
    initComponent: function () {
        var me = this;
        me.items = [me.getForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSubmit },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            App.AjaxGet('/api/services/app/project/Get?id=' + me.projectId, function (data) {
                me.form.getForm().setValues(data.result);
                Ext.getCmp("txt_productShow").setValue(data.result.productNo + '<a href="#">编辑</a>');
            });
        }
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        hidden: true,
                        name: 'id',
                        value: 0
                    },
                    {
                        xtype: 'container',
                        anchor: '100%',
                        layout: 'hbox',
                        items: [
                            {
                                xtype: 'container',
                                flex: 1,
                                layout: 'anchor',
                                items: [
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '项目编号',
                                        name: 'projectNo'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        id: 'txt_productShow',
                                        fieldLabel: '产品号',
                                        value: '<a href="#">编辑</a>',
                                        listeners: {
                                            afterrender: function (component) {
                                                component.getEl().on('click', function () {
                                                    var win = Ext.create("app.prm.project.EditProduct");
                                                    win.on("savesuccess", function (productNo) {
                                                        Ext.getCmp("txt_ProductNo").setValue(productNo);
                                                        component.setValue(productNo + '<a href="#">编辑</a>');
                                                        win.close();
                                                    });
                                                    win.show();
                                                });
                                            }
                                        }
                                    },
                                    {
                                        xtype: 'hidden',
                                        id: 'txt_ProductNo',
                                        name: 'productNo'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '客户',
                                        name: 'customer'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '研发中心',
                                        name: 'rdCenter'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '质量标准',
                                        name: 'qualityStandard'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '项目性质',
                                        name: 'projectNature'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '计划人力成本',
                                        name: 'targetWorkCost'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '目标完成量',
                                        name: 'targetOutPut'
                                    },
                                    {
                                        xtype: 'datefield',
                                        editable: false,
                                        format: 'Y-m-d',
                                        allowBlank: false,
                                        fieldLabel: '计划开始时间',
                                        name: 'planStartDate'
                                    }
                                ]
                            },
                            {
                                xtype: 'container',
                                flex: 1,
                                layout: 'anchor',
                                items: [
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '项目名称',
                                        name: 'projectName'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '中试地点',
                                        name: 'address'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '客户编号',
                                        name: 'customeCode'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '研究室',
                                        name: 'lab'
                                    },
                                    {
                                        xtype: 'combo',
                                        fieldLabel: '项目任务',
                                        name: 'taskType',
                                        store: ['小试', '中试', '其它']
                                    },
                                    {
                                        xtype: 'datefield',
                                        editable: false,
                                        format: 'Y-m-d',
                                        allowBlank: false,
                                        fieldLabel: '要求完成时间',
                                        name: 'targetEndDate'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '目标项目成本',
                                        name: 'targetCost'
                                    },
                                    {
                                        xtype: 'textfield',
                                        fieldLabel: '目标原料成本',
                                        name: 'targetMaterialCost'
                                    },
                                    {
                                        xtype: 'datefield',
                                        editable: false,
                                        format: 'Y-m-d',
                                        allowBlank: false,
                                        fieldLabel: '计划结束时间',
                                        name: 'planEndDate'
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        xtype: 'textarea',
                        fieldLabel: '备注',
                        height: 100,
                        anchor: '85%',
                        name: 'remark'
                    }
                ]
            });
        }
        return this.form;
    },
    onSubmit: function () {
        var me = this;
        var json = me.getForm().getForm().getValues();
        App.AjaxPost('/api/services/app/project/EditProject', json, function () {
            me.fireEvent("savesuccess", json);
        });
    }
});